const cardConfig = {
    // 卡牌基本屬性配置
    cards: {
        1: {"name": "曾浩明", "bond1": "二刺螈", "bond2": "枪神", "attack": 1, "defense": 3, "count": 5,"cost":2, "image": "card/1.png"},
        2: {"name": "邓焱嘉", "bond1": "TC", "bond2": "枪神", "attack": 3, "defense": 2, "count": 5,"cost":3, "image": "card/2.png"},
        3: {"name": "国嘉豪", "bond1": "山河四省", "bond2": "恋爱ING", "attack": 2, "defense": 2, "count": 5, "cost":2,"image": "card/3.png"},
        4: {"name": "李冠威", "bond1": "学学学", "bond2": "练练练", "attack": 3, "defense": 2, "count": 5,"cost":3, "image": "card/4.png"},
        5: {"name": "李嘉信", "bond1": "练练练", "bond2": "恋爱ING", "attack": 1, "defense": 1, "count": 5,"cost":1, "image": "card/5.png"},
        6: {"name": "刘赟豪", "bond1": "学学学", "bond2": "练练练", "attack": 5, "defense": 4, "count": 5,"cost":5, "image": "card/6.png"},
        7: {"name": "马超", "bond1": "枪神", "bond2": "练练练", "attack": 3, "defense": 1, "count": 5,"cost":2, "image": "card/7.png"},
        8: {"name": "芮桂锋", "bond1": "二刺螈", "bond2": "科代表", "attack": 3, "defense": 2, "count": 5, "cost":3, "image": "card/8.png"},
        9: {"name": "石承坤", "bond1": "二刺螈", "bond2": "枪神", "attack": 2, "defense": 1, "count": 5, "cost":1, "image": "card/9.png"},
        10: {"name": "时浩轩", "bond1": "恋爱ING", "bond2": "枪神", "attack": 2, "defense": 1, "count": 5, "cost":1, "image": "card/10.png"},
        11: {"name": "孙宁浩", "bond1": "练练练", "bond2": "山河四省", "attack": 4, "defense": 3, "count": 5, "cost":4, "image": "card/11.png"},
        12: {"name": "王俊", "bond1": "学学学", "bond2": "科代表", "attack": 3, "defense": 2, "count": 5, "cost":3, "image": "card/12.png"},
        13: {"name": "王生晖", "bond1": "山河四省", "bond2": "TC", "attack": 3, "defense": 1, "count": 5, "cost":2, "image": "card/13.png"},
        14: {"name": "许城玮", "bond1": "山河四省", "bond2": "枪神", "attack": 2, "defense": 2, "count": 5, "cost":2, "image": "card/14.png"},
        15: {"name": "杨知升", "bond1": "学学学", "bond2": "TC", "attack": 4, "defense": 3, "count": 5, "cost":4, "image": "card/15.png"},
        16: {"name": "尹奥", "bond1": "山河四省", "bond2": "TC", "attack": 3, "defense": 4, "count": 5, "cost":1, "image": "card/16.png"},
        17: {"name": "张哲嘉", "bond1": "枪神", "bond2": "练练练", "attack": 2, "defense": 1, "count": 5, "cost":1, "image": "card/17.png"},
        18: {"name": "周洁", "bond1": "学学学", "bond2": "科代表", "attack": 1, "defense": 2, "count": 5, "cost":1, "image": "card/18.png"}
    },

    // 羈絆效果配置
    bonds: {
        "二刺螈": {
            "枪神": { attack: 0, defense: 2 },
            "科代表": { attack: 0, defense: 2 },
            "练练练": { attack: 0, defense: 2 },
            "山河四省": { attack: 0, defense: 2 },
            "学学学": { attack: 0, defense: 2 },
            "恋爱ING": { attack: 0, defense: 2 },
            "TC": { attack: 0, defense: 2 }
        },
        "枪神": {
            "二刺螈": { attack: 1, defense: 1 },
            "科代表": { attack: 1, defense: 1 },
            "练练练": { attack: 1, defense: 1 },
            "山河四省": { attack: 1, defense: 1 },
            "学学学": { attack: 1, defense: 1 },
            "恋爱ING": { attack: 1, defense: 1 },
            "TC": { attack: 1, defense: 1 }
        },
        "山河四省": {
            "二刺螈": { attack: 0, defense: 3 },
            "科代表": { attack: 0, defense: 3 },
            "练练练": { attack: 0, defense: 3 },
            "枪神": { attack: 0, defense: 3 },
            "学学学": { attack: 0, defense: 3 },
            "恋爱ING": { attack: 0, defense: 3 },
            "TC": { attack: 0, defense: 3 }
        },
        "科代表": {
            "二刺螈": { attack: 2, defense: 0 },
            "练练练": { attack: 2, defense: 0 },
            "山河四省": { attack: 2, defense: 0 },
            "枪神": { attack: 2, defense: 0 },
            "学学学": { attack: 2, defense: 0 },
            "恋爱ING": { attack: 2, defense: 0 },
            "TC": { attack: 2, defense: 0 }
        },
        "学学学": {
            "二刺螈": { attack: 2, defense: 0 },
            "科代表": { attack: 2, defense: 0 },
            "练练练": { attack: 2, defense: 0 },
            "山河四省": { attack: 2, defense: 0 },
            "枪神": { attack: 2, defense: 0 },
            "恋爱ING": { attack: 2, defense: 0 },
            "TC": { attack: 2, defense: 0 }
        },
        "练练练": {
            "二刺螈": { attack: 2, defense: 2 },
            "科代表": { attack: 2, defense: 2 },
            "山河四省": { attack: 2, defense: 2 },
            "枪神": { attack: 2, defense: 2 },
            "学学学": { attack: 2, defense: 2 },
            "恋爱ING": { attack: 2, defense: 2 },
            "TC": { attack: 2, defense: 2 }
        },
        "恋爱ING": {
            "二刺螈": { attack: -1, defense: -1 },
            "科代表": { attack: -1, defense: -1 },
            "练练练": { attack: -1, defense: -1 },
            "山河四省": { attack: -1, defense: -1 },
            "枪神": { attack: -1, defense: -1 },
            "学学学": { attack: -1, defense: -1 },
            "TC": { attack: -1, defense: -1 }
        },
        "TC": {
            "二刺螈": { attack: 3, defense: 0 },
            "科代表": { attack: 3, defense: 0 },
            "练练练": { attack: 3, defense: 0 },
            "山河四省": { attack: 3, defense: 0 },
            "枪神": { attack: 3, defense: 0 },
            "学学学": { attack: 3, defense: 0 },
            "恋爱ING": { attack: 3, defense: 0 }
        }
    },

    // 獲取卡牌屬性
    getCardInfo: function(cardId) {
        //console.log('getCardInfo 被調用，參數:', cardId);
        //console.log('卡牌配置:', this.cards);
        const card = this.cards[cardId];
        //console.log('找到的卡牌:', card);
        return card;
    },

    // 減少卡牌數量
    decreaseCardCount: function(cardId) {
        if (this.cards[cardId] && this.cards[cardId].count > 0) {
            this.cards[cardId].count--;
            return true;
        }
        return false;
    },

    // 計算卡牌實際戰鬥力（考慮羈絆效果）
    calculateCardPower: function(cardId, battleCards) {
        const card = this.cards[cardId];
        if (!card) return { attack: 0, defense: 0 };

        // 計算羈絆加成
        const bondBonus = this.calculateBondBonus(card, battleCards);
        
        // 檢查是否為合成卡牌
        const isMerged = card.isMerged;
        const multiplier = isMerged ? 2 : 1;
        
        return {
            attack: (card.attack + bondBonus.attack) * multiplier,
            defense: (card.defense + bondBonus.defense) * multiplier
        };
    },

    // 計算羈絆加成
    calculateBondBonus: function(card, battleCards) {
        let attackBonus = 0;
        let defenseBonus = 0;

        // 獲取場上所有不同類型的卡牌
        const uniqueCards = new Set(battleCards);
        
        // 計算每個羈絆類型出現的次數（只計算不同類型的卡牌）
        const bondCounts = {};
        uniqueCards.forEach(cardId => {
            const battleCard = this.cards[cardId];
            if (!battleCard) return;
            
            // 統計每個羈絆出現的次數
            [battleCard.bond1, battleCard.bond2].forEach(bond => {
                if (!bond) return;
                bondCounts[bond] = (bondCounts[bond] || 0) + 1;
            });
        });

        // 如果場上有2張或以上不同類型的卡牌具有相同羈絆，則應用加成
        if (bondCounts[card.bond1] >= 2) {
            const bond1Bonus = this.bonds[card.bond1][card.bond2];
            attackBonus += bond1Bonus.attack;
            defenseBonus += bond1Bonus.defense;
        }

        if (bondCounts[card.bond2] >= 2) {
            const bond2Bonus = this.bonds[card.bond2][card.bond1];
            attackBonus += bond2Bonus.attack;
            defenseBonus += bond2Bonus.defense;
        }

        return { attack: attackBonus, defense: defenseBonus };
    }
}; 